//
//  SingerController.m
//  Kugou-OC
//
//  Created by BH on 16/5/27.
//  Copyright © 2016年 Sunny. All rights reserved.
//

#import "MLSingerController.h"
#import "GlobalDefine.h"
#import <SDAutoLayout/UIView+SDAutoLayout.h>

@interface MLSingerController ()<UITableViewDataSource,UITableViewDelegate>
{
    
}

@property(nonatomic,strong)UITableView *table;
@property(nonatomic,strong)NSDictionary *rowsTitleDict;

@end

@implementation MLSingerController

-(id)init{
    self = [super init];
    if (self) {
        _rowsTitleDict = [NSDictionary dictionaryWithObjectsAndKeys:@[@"我关注的歌手"],@(0),@[@"华语男歌手",@"华语女歌手",@"华语组合"],@(1),@[@"日韩男歌手",@"日韩女歌手",@"日韩组合"],@(2),@[@"欧美男歌手",@"欧美女歌手",@"欧美组合"],@(3), nil];
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-90-64-30) style:UITableViewStylePlain];
    _table.dataSource = self;
    _table.delegate = self;
    [self.view addSubview:_table];

}

#pragma mark - UITableview datasource & delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return [_rowsTitleDict allKeys].count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSArray *rowsArray = [_rowsTitleDict objectForKey:@(section)];
    return rowsArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 15;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"MLSingerCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else{
        for (UIView *subView in cell.contentView.subviews) {
            [subView removeFromSuperview];
        }
    }
    
    UILabel *titleLab = ALLOC(UILabel);
    titleLab.font = TITLE_THIRD_FONT;
    [cell.contentView addSubview:titleLab];
    
    titleLab.sd_layout.leftSpaceToView(cell.contentView,10).rightEqualToView(cell.contentView).topEqualToView(cell.contentView).bottomEqualToView(cell.contentView);
    
    NSArray *rowsArray = [_rowsTitleDict objectForKey:@(indexPath.section)];
    titleLab.text = rowsArray[indexPath.row];
    
    return cell;
}


@end
